<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .menu{
            width: 100%;
            height: 40px;
            display: flex;
        }
        .menu .item{
            flex: 1;
            background-color: black;
            text-align: center;
            color: blanchedalmond;
            line-height: 40px;
        }
        .menu .item ul  {
            overflow: hidden;
        }
        .menu .item  li{
            background-color: black;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul class="menu">
            <li class="item" v-for="item in list" >
                <span @mouseover="changeIndex(item.id)">{{item.msg}}</span>
                <ul v-show="activeIndex==item.id" @mouseleave="out" :style="{height:item.list.length*40+'px'}">
                    <li v-for="info in item.list">
                        {{info.msg}}
                    </li>
                 
                </ul>
            </li>
         
        </ul>
    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            activeIndex: 0,
            list: [{ id: 1, msg: "菜单1", list: [{ id: 11, msg: "菜单1.1" }, { id: 12, msg: "菜单1.2" }] }, { id: 2, msg: "菜单2", list: [{ id: 21, msg: "菜单2.1" }, { id: 22, msg: "菜单2.2" }, { id: 23, msg: "菜单2.3" }] }, { id: 3, msg: "菜单3", list: [{ id: 31, msg: "菜单3.1" }, { id: 32, msg: "菜单3.2" }, { id: 33, msg: "菜单3.3" }] }, { id: 4, msg: "菜单4", list: [{ id: 41, msg: "菜单4.1" }, { id: 42, msg: "菜单4.2" }, { id: 43, msg: "菜单4.3" }] }]
        },
        methods: {
            changeIndex(id) {
                this.activeIndex = id;
            },
            out(){
                this.activeIndex = 0;
                }
        }
    })
</script>

</html>